package com.tjsinfo.tjsoa.fileExpress.action;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.fileExpress.bo.IFileExpressUserSizeBo;
import com.tjsinfo.tjsoa.fileExpress.vo.TjsUserEmail;
import com.tjsinfo.tjsoa.system.vo.User;

public class LoginAddressListAction extends Action{
	//private ITjsMessageBo tjsMessageBo;
	private IFileExpressUserSizeBo expressUserSizeBo;
	
	public void setExpressUserSizeBo(IFileExpressUserSizeBo expressUserSizeBo) {
		this.expressUserSizeBo = expressUserSizeBo;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		request.setAttribute("first", "shi");
		
		ResourceBundle bundle = ResourceBundle.getBundle("com.tjsinfo.tjsoa.fileExpress.properties.FileExpress");
		String path = bundle.getString("linshiFile");
		File file=new File(path); 
		String test[]; 
		test=file.list();
		try {
			if (test.length>0) {
				for (int i = 0; i < test.length; i++) {
					String strdos = "cmd /c del \""+path+"\\"+test[i]+"\"";
					Process process;
					try {
						process = Runtime
								.getRuntime().exec(strdos);
						process.waitFor();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		} catch (RuntimeException e1) {
			String strdos = "cmd /c md \""+path+"\\\"";
			Process process;
			try {
				process = Runtime
						.getRuntime().exec(strdos);
				process.waitFor();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//tjsMessageBo.deleteNewMessageAndModle(SessionUser.getUserId(request), "（文件速递）");
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		TjsUserEmail email = expressUserSizeBo.fingByUserId(user.getUser_id());
		Integer max = email.getMaxExpress();
		if(max==null)max = 0;
		request.setAttribute("maxExpress", (new DecimalFormat("###,###,###").format(max/1024/1024)).toString());
		return mapping.findForward("ok");
	}

	/*public ITjsMessageBo getTjsMessageBo() {
		return tjsMessageBo;
	}

	public void setTjsMessageBo(ITjsMessageBo tjsMessageBo) {
		this.tjsMessageBo = tjsMessageBo;
	}*/
}
